********************************************************************************
*****JOP Replication File - Canton Matching in Senegal - Main Paper*************
*****Lindsey Pruett - September 2023********************************************
*****Stata 17.0*****************************************************************
********************************************************************************


clear

use "C:\Users\ldpru\OneDrive\Desktop\Replication_JOP\JOP_Pruett_cantons.dta"

*Figure 7: Coarsened Exact Matching 
	
	*note: Exact matching on population and border proximity and year

cem Border_20 pop_quartile Year, tr(rail_5)
reg abs_pop rail_5 [iweight=cem_weights]
estimates store A

reg abs_pop rail_5 Border_20 Soil_jed H2o pop_quartile W_Town [iweight=cem_weights]
estimates store B

cem Border_20 pop_quartile Year, tr(rail_10)
reg abs_pop rail_10 [iweight=cem_weights]
estimates store C

reg abs_pop rail_10 Border_20 Soil_jed H2o pop_quartile W_Town [iweight=cem_weights]
estimates store D

cem Border_20 pop_quartile Year, tr(rail_15)
reg abs_pop rail_15 [iweight=cem_weights]
estimates store E

reg abs_pop rail_15 Border_20 Soil_jed H2o pop_quartile W_Town [iweight=cem_weights]
estimates store F


cem Border_20 pop_quartile, tr(rail_20)
reg abs_pop rail_20 [iweight=cem_weights]
estimates store G

reg abs_pop rail_20 Border_20 Soil_jed H2o pop_quartile W_Town [iweight=cem_weights]
estimates store H


coefplot A B, bylabel(5 km.) || C D, bylabel(10 km.) || E F, bylabel(15 km.) || G H, bylabel(20 km.) scheme(s1mono) xline(0) drop(_cons) order(rail_5 rail_10 rail_15 rail_20 Border_20 pop_quartile W_Town Soil_jed H2o) byopts(col(4)) xsize(8) 

	*note: remove labels for A and B, clean up labels

drop cem_weights cem_matched cem_strata

	
	
*Descriptive Statistics and Checks in Main Paper********************************

*Balance in matching
ttest Border_20, by(rail_5)
ttest W_Town, by(rail_5)
ttest pop_quartile, by(rail_5)
ttest H2o, by(rail_5)
ttest Soil_jed, by(rail_5)

ttest Border_20, by(rail_20)
ttest W_Town, by(rail_20)
ttest pop_quartile, by(rail_20)
ttest H2o, by(rail_20)
ttest Soil_jed, by(rail_20)
		
		*note: presence of surface water and proximity to border are not balanced
		*note: measured balance at 5km and 20 km. Results similar

*Descriptive Statistics in Fatick, Kaolack, Bakel and Kidira

sum abs_pop if Canton=="Fatick" & Year==1933
sum abs_pop if Canton=="Kaolack" & Year==1933
sum abs_pop if Canton=="Bakel" & Year==1933
sum abs_pop if Canton=="Kidiri" & Year==1933


*Mann Whitney Test on Borders
ranksum abs_pop, by(border_20_40)
